package Program;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.swing.JFrame;

import GUI.Frame;


public class Majn {

	/**
	 * @param args
	 */
	

	
	public static CopyOnWriteArrayList<CopyOnWriteArrayList<Integer>> kliki = new CopyOnWriteArrayList<CopyOnWriteArrayList<Integer>>();
	public static CopyOnWriteArrayList<CopyOnWriteArrayList<Integer>> mkliki = new CopyOnWriteArrayList<CopyOnWriteArrayList<Integer>>();
	public static int mknr = 0;
	public static int n = 10;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	
		byte[][] G = new Graph().newGraph(n);

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(G[i][j] == 8) 
					System.out.print("   ");
				else
					System.out.print(" " + G[i][j] + " ");
				
			}
			System.out.println();
		}
		
		for(int i = 0; i < n; i++) {
			new Thread(new Bleble(i, G)).start();
		}

		while(Thread.activeCount() > 1) {

		}
		System.out.println("endac");
		
		while(!Bleble.stopnie.isEmpty()) {
			ArrayList<Integer> current = Bleble.stopnie.get(0);
			for(ArrayList<Integer> wierzcholek: Bleble.stopnie) {
				if(current.size()<=wierzcholek.size()) {
					current = wierzcholek;
				}
			}
			Bleble.stopnie.remove(current);
			new Thread(new Own(current, G)).start();
			System.out.println(current.size());
		}
		while(Thread.activeCount() > 1) {

		}
		CopyOnWriteArrayList<Integer> mklika =  new CopyOnWriteArrayList<Integer>();
		for(CopyOnWriteArrayList<Integer> klika : Majn.kliki) {
			System.out.print("\n Size " + klika.size() + "\nW: ");
			if(mklika.size()<=klika.size())
				mklika = klika;
			for(int w : klika) {
				System.out.print(" " + w);
			}
			System.out.println();
		}
		Majn.mkliki.add(mklika);
		
		
		for(CopyOnWriteArrayList<Integer> klika : Majn.kliki) {
			
			if(mklika.size()==klika.size()) {
			int different = 0;
			for(CopyOnWriteArrayList<Integer> mk : mkliki) {
				for(int i : mk) {
					for(int j : klika) {
						if(i==j) {
							different++;
						}
					}
				}
			}
			if(different < mklika.size()) mkliki.add(klika);
			
				
			}
		}
		

			
		Frame ramka = new Frame(G);
		ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		ramka.show();//set visible true
	}

}
